import request from '@/utils/request'

export function fetchTags(teamId) {
  return request({
    url: '/announcementtags/teams/' + teamId,
    method: 'get'
  })
}

export function fetchOnlyTags(teamId) {
  return request({
    url: '/announcementtags/teams/' + teamId,
    method: 'get',
    params: { onlyTags: true }
  })
}

export function addTag(name) {
  return request({
    url: '/announcementtags',
    method: 'post',
    data: { name }
  })
}

export function delTag(tagId) {
  return request({
    url: '/announcementtags/' + tagId,
    method: 'delete'
  })
}

export function updateTag(tagId, name) {
  return request({
    url: '/announcementtags/' + tagId,
    method: 'patch',
    data: { name }
  })
}

export function fetchAllAnn(teamId, page, per_page) {
  return request({
    url: '/announcements/teams/' + teamId,
    params: { page, per_page },
    method: 'get'
  })
}

export function removeAnn(annId) {
  return request({
    url: '/announcements/' + annId,
    method: 'delete'
  })
}

export function addAnnInTeam(announcement, teamId) {
  return request({
    url: '/announcements/teams/' + teamId,
    method: 'post',
    data: { ...announcement }
  })
}

export function fetchAnnById(annId) {
  return request({
    url: '/announcements/' + annId,
    method: 'get'
  })
}
